//
//  MyAccountVC.m
//  MRBang
//
//  Created by 铅笔 on 16/4/20.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "MyAccountVC.h"
#import "MyBankCardVC.h"//我的银行卡
#import "MyLoanVC.h"//我的贷款
#import "RechargeMentionDetailsVC.h"//充值、提现明细

@interface MyAccountVC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView_MyAccount;

@end

@implementation MyAccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的账户";
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
    [self initWithMyAccountViewSubviews];
    
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.tabBarController.tabBar.hidden = YES;
}

#pragma mark --- 创建视图界面
- (void) initWithMyAccountViewSubviews
{
    self.tableView_MyAccount = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [self.view addSubview:self.tableView_MyAccount];
    self.tableView_MyAccount.dataSource = self;
    self.tableView_MyAccount.delegate = self;
    self.tableView_MyAccount.showsVerticalScrollIndicator = NO;
    self.tableView_MyAccount.separatorStyle =UITableViewCellSeparatorStyleNone;
    self.tableView_MyAccount.backgroundColor = COLOR_EVERYVIEWBG;
   
}

#pragma  mark ----UITableViewDataSource

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 5;
    
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellFillInInformationID = @"cellFillInInformationID";
    
    UITableViewCell *cell_fillInfo = [tableView cellForRowAtIndexPath:indexPath];
    if (cell_fillInfo==nil) {
        cell_fillInfo = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellFillInInformationID];
    }
    
    UIView *view_line = [[UIView alloc] init];
    [cell_fillInfo.contentView addSubview:view_line];
    view_line.backgroundColor = [BaseViewController colorWithHexString:@"#EEEFF1"];
    
    cell_fillInfo.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSArray *array_title = @[@"可用余额",@"还款提醒",@"充值、提现明细"];
    
    //label
    UILabel *label_leftTitle = [[UILabel alloc] initWithFrame:CGRectMake(27*PROPORTION_WIDTH, 35*PROPORTION_WIDTH, 210*PROPORTION_WIDTH, 32*PROPORTION_WIDTH)];
    [cell_fillInfo addSubview:label_leftTitle];
    
    label_leftTitle.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];
    
    //label right
    UILabel *label_rightContent = [[UILabel alloc] initWithFrame:CGRectMake(label_leftTitle.right+30*PROPORTION_WIDTH, label_leftTitle.y,330*PROPORTION_WIDTH, 32*PROPORTION_WIDTH)];
    [cell_fillInfo addSubview:label_rightContent];
    label_rightContent.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
    label_rightContent.textColor = [BaseViewController colorWithHexString:@"#e8482e"];

    if (indexPath.row==0) {
        
       label_leftTitle.text = array_title[0];
       label_leftTitle.frame = CGRectMake(27*PROPORTION_WIDTH, 45*PROPORTION_WIDTH, 110*PROPORTION_WIDTH, 32*PROPORTION_WIDTH);
       view_line.frame = CGRectMake(0, (142-22)*PROPORTION_WIDTH, kScreenWidth, 22*PROPORTION_WIDTH);
        label_rightContent.frame = CGRectMake(label_leftTitle.right+12*PROPORTION_WIDTH, label_leftTitle.y,330*PROPORTION_WIDTH, 32*PROPORTION_WIDTH);
        
         label_rightContent.text = self.str_balance;
        
    }
    
    if (indexPath.row==1) {
        cell_fillInfo.backgroundColor = COLOR_EVERYVIEWBG;
        
        NSArray *array_name = @[@"我的贷款",@"我的银行卡"];
        NSArray *array_img = @[@"dollar",@"bankcard"];
        
        CGFloat buttonW = (kScreenWidth-3)/2;
        UILabel *label_text;
        label_text.backgroundColor = [UIColor greenColor];
        
        int count = 0;
        
        count = 2;
        
        CGFloat buttonY ;
        buttonY = 1;
        
        for (int i=0; i<count; i++) {
            UIButton *button_temp = [[UIButton alloc] initWithFrame:CGRectMake((buttonW+1)*i, buttonY, buttonW,230*PROPORTION_WIDTH)];
            [cell_fillInfo.contentView addSubview:button_temp];
            button_temp.backgroundColor = [UIColor whiteColor];
            
            [button_temp setImageEdgeInsets:UIEdgeInsetsMake(-13, 0, 15, 0)];
            [button_temp setImage:[UIImage imageNamed:array_img[i]] forState:UIControlStateNormal];
            
            //文字
            label_text = [[UILabel alloc] initWithFrame:CGRectMake(0, button_temp.frame.size.height-50, buttonW, 20)];
            [button_temp addSubview:label_text];
            label_text.text = array_name[i];
            label_text.textAlignment = NSTextAlignmentCenter;
            label_text.textColor = [BaseViewController colorWithHexString:@"#384056"];
            label_text.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];
            
            //此处优待优化
          
            button_temp.tag = 50+i;
           
            [button_temp addTarget:self action:@selector(clickDifferentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        
       }
    }
    
    if (indexPath.row==2) {
        view_line.frame = CGRectMake(0, (135-12)*PROPORTION_WIDTH, kScreenWidth, 12*PROPORTION_WIDTH);
        
        label_leftTitle.frame = CGRectMake(27*PROPORTION_WIDTH+kScreenWidth/2, 45*PROPORTION_WIDTH, 110*PROPORTION_WIDTH, 32*PROPORTION_WIDTH);
        label_leftTitle.text = @"累计收益";
        
        label_rightContent.frame = CGRectMake(label_leftTitle.right+12*PROPORTION_WIDTH, label_leftTitle.y,330*PROPORTION_WIDTH, 32*PROPORTION_WIDTH);
        label_rightContent.text = @"0.00元";
        
        //button
        UIButton *button_money = [[UIButton alloc] initWithFrame:CGRectMake(0,0, kScreenWidth/2, 125*PROPORTION_WIDTH)];
        [cell_fillInfo.contentView addSubview:button_money];
        [button_money setTitle:@"在投资金" forState:UIControlStateNormal];
        [button_money setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
        [button_money.titleLabel setFont:[UIFont systemFontOfSize:PROPORTION_WIDTH*24]];
        [button_money setTitleColor:[BaseViewController colorWithHexString:@"#384056"] forState:UIControlStateNormal];
        [button_money setImage:[UIImage imageNamed:@"money"] forState:UIControlStateNormal];

    }
    
    if (indexPath.row==4||indexPath.row==3) {
        label_leftTitle.text = array_title[indexPath.row-2];
        view_line.frame = CGRectMake(0, 95*PROPORTION_WIDTH-1, kScreenWidth, 1.0);
        
//        UILabel *label_detial;
//        if (indexPath.row==3) {
//            //label
//            label_detial = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth-116*PROPORTION_WIDTH, 35*PROPORTION_WIDTH, 50*PROPORTION_WIDTH, 30*PROPORTION_WIDTH)];
//            [cell_fillInfo.contentView addSubview:label_detial];
//            label_detial.text = @"明细";
//            label_detial.font = [UIFont systemFontOfSize:24*PROPORTION_WIDTH];
//            label_detial.textColor = [BaseViewController colorWithHexString:@"#666666"];
//        }
        
        //button
        UIButton *button_rightArrow = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-51*PROPORTION_WIDTH, 32*PROPORTION_WIDTH-2.2, 20, 20)];
        [cell_fillInfo.contentView addSubview:button_rightArrow];
        [button_rightArrow setImage:[UIImage imageNamed:@"return_right"] forState:UIControlStateNormal];
    }
    
    return cell_fillInfo;
    
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==4) {
        RechargeMentionDetailsVC *rechargeView = [[RechargeMentionDetailsVC alloc] init];
        [self.navigationController pushViewController:rechargeView animated:YES];
    }
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        return  142*PROPORTION_WIDTH;
    }
    if (indexPath.row==1) {
        return 235*PROPORTION_WIDTH;
    }
    if (indexPath.row==2) {
        return 135*PROPORTION_WIDTH;
    }
    else
    {
        return 95*PROPORTION_WIDTH;
    }
}

#pragma mark----进入不同的页面
- (void) clickDifferentButtonAction:(UIButton *)sender
{
    if (sender.tag==51) {
        MyBankCardVC *myBankView = [[MyBankCardVC alloc] init];
        [self.navigationController pushViewController:myBankView animated:YES];
    }
    if (sender.tag==50) {
        MyLoanVC *myLoan = [[MyLoanVC alloc] init];
        [self.navigationController pushViewController:myLoan animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
